﻿using LY.Manage.IDAL;
using LY.Manage.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LY.Manage.DAL
{

    //注意这里 先继承 BaseDal ,后实现 IUserInfo
    //IUserInfoDal 已经继承了 IBaseDal中的方法,所以BaseDal不需要再次继承IBaseDal了
   public partial  class UserInfoDal:BaseDal<UserInfo>,IUserInfoDal
    {


        /*
         * 每个类都要实现下面的方法 所以要进行封装 BaseDal
        
        OAEntities Db = new OAEntities();


        /// <summary>
        /// 查询过滤
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <returns></returns>
        public IQueryable<UserInfo> LoadEntities(System.Linq.Expressions.Expression<Func<UserInfo, bool>> whereLambda)
        {
            return Db.UserInfo.Where<UserInfo>(whereLambda);
        }

    
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <typeparam name="s"></typeparam>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <param name="whereLambda"></param>
        /// <param name="orderLambda"></param>
        /// <param name="isAsc"></param>
        /// <returns></returns>
        public IQueryable<UserInfo> LoadPageEntities<s>(int pageIndex, int pageSize, out int totalCount, System.Linq.Expressions.Expression<Func<UserInfo, bool>> whereLambda, System.Linq.Expressions.Expression<Func<UserInfo, s>> orderLambda, bool isAsc)
        {
            var temp = Db.UserInfo.Where<UserInfo>(whereLambda);
            totalCount = temp.Count();
            if (isAsc)
            {
                temp = temp.OrderBy<UserInfo, s>(orderLambda)
                    .Skip<UserInfo>((pageIndex - 1) * pageSize)
                    .Take<UserInfo>(pageSize);
 
            }
            else
            {
                temp = temp.OrderByDescending<UserInfo, s>(orderLambda)
                    .Skip<UserInfo>((pageIndex - 1) * pageSize)
                    .Take<UserInfo>(pageSize);

            }
            return temp;
        }

        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool DeleteEntity(UserInfo entity)
        {
            Db.Entry<UserInfo>(entity).State = System.Data.Entity.EntityState.Deleted;
            return Db.SaveChanges() > 0;
        }

        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool UpdateEntity(UserInfo entity)
        {
            Db.Entry<UserInfo>(entity).State = System.Data.Entity.EntityState.Modified;
            return Db.SaveChanges() > 0;
        }

        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public UserInfo AddEntity(UserInfo entity)
        {
            Db.UserInfo.Add(entity);
            Db.SaveChanges();
            return entity;
        }
        */

    }
}
